package com.shop2cn.iapi.promotion.serivce;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;



import com.google.gson.reflect.TypeToken;
import com.shop2cn.iapi.promotion.parameter.PlaceOrderCalculateReq;
import com.shop2cn.iapi.promotion.parameter.PlaceOrderCalculateResp;
import com.shop2cn.iapi.promotion.parameter.ProductDto;
import com.shop2cn.iapi.promotion.parameter.SellerProductDto;
import com.shop2cn.iapi.promotion.parameter.ShoppingCartCalculateReq;
import com.shop2cn.iapi.promotion.parameter.ShoppingCartCalculateResp;
import com.shop2cn.iapi.sellerpromotion.parameter.ConflictProduct;
import com.shop2cn.iapi.sellerpromotion.parameter.CreatePromotionBean;
import com.ymt.base.YmatouBaseCall;
import com.ymt.core.tool.FormatUtil;
import com.ymt.core.tool.Logger;
import com.ymttest.business.service.Shop2cnSellerPromotionCallService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.TestDataManager;
/**
*获取冲突商品列表
*FreeMaker Template自动生成代码
*/
public class CalcOrderPromotionInfoCall extends YmatouBaseCall{
	private static String opurl ="api/promotion/calcOrderPromotionInfo";
	
	public CalcOrderPromotionInfoCall() {
		super(EnvSetup.getSystemUrl("promotion_shop2cn_iapi"),opurl,"POST","JSON");
	}
	@Override
	public void addDefHeader() {
		client.addHeader("Accept","text/xml,text/javascript,text/html,application/json");
		client.addHeader("Content-Type", "application/json; charset=UTF-8");
	}
	public PlaceOrderCalculateResp getData() {
		PlaceOrderCalculateResp data = null;
        try {
        	String data2=getJsonObject().get("Data").getAsJsonObject().toString();
        	data=(PlaceOrderCalculateResp) FormatUtil.GSONToObject(data2, new TypeToken<PlaceOrderCalculateResp>() {}.getType());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return data;
	}
	public String getCode() {
		return getString("Code");
	}
	public String getMsg() {
		return getString("Msg");
	}
	public static void main(String [] args) throws Exception {
		Integer mchId = GodmchManageCallService.CreateSellerMch();
		CreatePromotionBean createpromotionBean = Shop2cnSellerPromotionCallService.initCreatePromotionBean(mchId, 4);
		Integer promotionId = Shop2cnSellerPromotionCallService.CreatepromotionCall(createpromotionBean);
		
		CalcOrderPromotionInfoCall CalcOrderPromotionInfoCall=new CalcOrderPromotionInfoCall();
		PlaceOrderCalculateReq PlaceOrderCalculateReq=new PlaceOrderCalculateReq();
		PlaceOrderCalculateReq.setBuyerId(111);
		List<SellerProductDto> sellerProductDtos=new ArrayList<SellerProductDto>();
		SellerProductDto sellerProductDto=new SellerProductDto();
		sellerProductDto.setSellerId(mchId);
		List<ProductDto> productDtos=new ArrayList<ProductDto>();
		ProductDto productDto=new ProductDto();
		productDto.setProductId("tpid"+TestDataManager.getRandomNum(10));
		productDto.setCatalogId("tcid"+TestDataManager.getRandomNum(10));
		productDto.setCurrency("CNY");
		productDto.setProductQty(101);
//		productDto.setProductTotalPrice(BigDecimal.valueOf(101));
		productDto.setProductUnitPrice(BigDecimal.valueOf(1));
		productDto.setShoppingCartProductNo("1");
//		productDto.setPromotionValue(BigDecimal.valueOf(10));
		productDtos.add(productDto);
		sellerProductDto.setProductDtos(productDtos);
		sellerProductDtos.add(sellerProductDto);
		PlaceOrderCalculateReq.setSellerProductDtos(sellerProductDtos);
		CalcOrderPromotionInfoCall.setData(PlaceOrderCalculateReq);
		CalcOrderPromotionInfoCall.callService();
		Logger.debug("data:"+FormatUtil.beanToGSONString(CalcOrderPromotionInfoCall.getData()));
	}
}